﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using RealtorsPortal.Business_Logic_Layer;

namespace RealtorsPortal.AdminCP
{
    public partial class FeaturedAds : System.Web.UI.Page
    {
        AdvertisementsDAL advd = new AdvertisementsDAL();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                this.LoadAndBindData();
            }
        }

        private void LoadAndBindData()
        {
            grvFeaturedAds.DataSource = advd.GetFeaturedAdsDataTable();
            grvFeaturedAds.DataBind();
        }

        protected void grvManageAdver_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            if (e.CommandName == "BrowseComponent")
            {
                int index = Convert.ToInt32(e.CommandArgument);
                string AdvId = grvFeaturedAds.DataKeys[index].Value.ToString();
                //Server.Transfer("~/AdminCP/AdvertisementDetails.aspx?ID=" + AdvId);
                Response.Write("<script>");
                Response.Write("window.open('../Detail.aspx?AdvId=" + AdvId + "','_blank')");
                Response.Write("</script>");
            }
            else if (e.CommandName == "DisableComponent")
            {
                int index = Convert.ToInt32(e.CommandArgument);
                string AdvId = grvFeaturedAds.DataKeys[index].Value.ToString();
                int id = int.Parse(AdvId);
                advd.DisableFeatured(id);
                this.LoadAndBindData();
            }
        }
    }
}